#include "stdafx.h"
#include "ChartSingleData.h"
#include "ChartMultiData.h"


CChartSingleData::CChartSingleData()
{
	S = 0;
	E = 0;
	for (int i = 0; i < MAX_COUNT; i++)
	{
		Date[i] = 0;
		Time[i] = 0;
		D[i] = 0;
	}
}


CChartSingleData::~CChartSingleData()
{
}

double CChartSingleData::AddData(double a_NewData)
{
	if (E >= MAX_COUNT)
		return D[E-1];
	return D[E++] = a_NewData;
}

double CChartSingleData::AddData(long a_Date, long a_Time, double a_Data)
{
	if (E >= MAX_COUNT)
		return D[E-1];

	Date[E] = a_Date;
	Time[E] = a_Time;
	D[E] = a_Data;
	E++;
	return a_Data;
}

void CChartSingleData::SetData(int a_Index, long a_Date, long a_Time, double a_Data)
{
	if (a_Index < 0 || a_Index >(sizeof(D) / sizeof(D[0])))
		return;

	Date[a_Index] = a_Date;
	Time[a_Index] = a_Time;
	D[a_Index] = a_Data;
}

void CChartSingleData::Init(int a_S, int a_E)
{
	S = a_S;
	E = a_E;
}

void CChartSingleData::Init(CChartMultiData* a_Data, int a_S, int a_E)
{
	if (a_Data)
	{
		S = a_S;
		E = a_E;
		for (int i = 0; i < a_S; i++)
		{
			Date[i] = a_Data->Date[i];
			Time[i] = a_Data->Time[i];
			D[i] = a_Data->Close[i];
		}
	}
}

void CChartSingleData::SetDataWithLastIndex(int a_Index, long a_Date, long a_Time, double a_Data)
{
	if (a_Index < 0 || a_Index >(sizeof(D) / sizeof(D[0])))
		return;

	Date[a_Index] = a_Date;
	Time[a_Index] = a_Time;
	D[a_Index] = a_Data;
	E = a_Index + 1;
}
